import { create } from "zustand";
import { immer } from "zustand/middleware/immer";



interface User {
  name: string,
  age: number,
  hobby: {
    sing: string;
    dance: string;
    rap: string;
    basketball: string;
  };
  setHobbyRap: () => void;
  setHobbyBasketball: () => void;
}
// const useUserStore = create<User>((set) => ({
//   //创建葫芦娃
//   gourd: {
//     oneChild: "大娃",
//     twoChild: "二娃",
//     threeChild: "三娃",
//     fourChild: "四娃",
//     fiveChild: "五娃",
//     sixChild: "六娃",
//     sevenChild: "七娃",
//   },
//   updateGourd: () =>
//     set((state) => ({
//       gourd: {
//         ...state.gourd, //先不进行状态合并  // [!code highlight]
//         oneChild: "大娃-超进化",
//       },
//     })),
// }));

// const useUserStore = create<User>()(immer(((set) => ({
//     //创建葫芦娃
//     gourd: {
//         oneChild: '大娃',
//         twoChild: '二娃',
//         threeChild: '三娃',
//         fourChild: '四娃',
//         fiveChild: '五娃',
//         sixChild: '六娃',
//         sevenChild: '七娃',
//     },
//     updateGourd: () => set((state) => {
//         state.gourd.oneChild = '大娃-超进化' //这儿不需要状态合并了需要修改什么值直接改就行了
//         state.gourd.twoChild = '二娃-谁来了'
//         state.gourd.threeChild = '三娃-我来了'
//     })
// }))))

const logger = (config) => (set, get, api) => config((...args) => {
    console.log(api)
    console.log('before', get())
    set(...args)
    console.log('after', get())
}, get, api)


const useUserStore = create<User>()(immer(logger((set) => ({
    name: '坤坤',
    age: 18,
    hobby: {
        sing: '坤式唱腔',
        dance: '坤式舞步',
        rap: '坤式rap',
        basketball: '坤式篮球'
    },
    setHobbyRap: (rap: string) => set((state) => {
        state.hobby.rap = rap
    }),
    setHobbyBasketball: (basketball: string) => set((state) => {
        state.hobby.basketball = basketball
    })
}))))



export default useUserStore;
